<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>角色信息</title>
</head>

<body>

    <div class="page-container">
        <div class="searcharea">
            <div class="st">
                <div class="sn">IP地址</div>
                <div class="idesc">查看客户端访问的IP情况，可以判断出谁在刷接口等</div>
            </div>
            <form id="formsearch">
                <div class="searchbox">

                    <select name="appname">
                        <option value="SmartShopApi">SmartShopApi</option>
                    </select>

                    <div class="timearea" style="display:flex;border:1px solid #888;border-radius: 4px;">
                        <select name="timetype" style="width:120px;border:none;outline:none;text-align: center;">
                            <option value="empty">报表时间</option>
                        </select>
                        <input type="text" name="daterange" readonly datas="" datae="" value=""
                            style="position:relative;flex:1;outline:none;border:none;border-radius: 4px; text-align: center;"
                            id="picker_date_range">
                    </div>
                    <input type="text" class="inputword" title="关键字搜索" placeholder="关键字搜索" value="">
                    <input type="button" class="btnsearch" onclick="_readpagedata(1);" value="查询">
                </div>
            </form>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                    <tr class="text-c">
                        <th></th>
                        <th>IP</th>
                        <th width="150">次数</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
        <div id="pagenumarea" class="pagenumarea"></div>
    </div>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/pickerdaterange/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->
    <script type="text/javascript" src="../lib/api.js"></script>
    <link href="../lib/page.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/page.min.js"></script>

    <script type="text/javascript" src="../lib/pickerdaterange/dateRange.js"></script>
    <link rel="stylesheet" href="../lib/pickerdaterange/dateRange.css">

    <script>
        var pageobject = null;
        var isselect = false;
        function _showpagedata(datas) {
            $("table").find("tbody").empty();
            var hstr = "";
            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];
                var htmlStr = '<tr class="text-c">';
                htmlStr += '<td></td>';
                htmlStr += '<td class="fleft">' + item.clientIp + '</td>';
                htmlStr += '<td>' + item.hitTime + '</td>';
                htmlStr += '<td></td>';
                htmlStr += '</tr>';
                hstr += htmlStr;
            }
            $("table").find("tbody").append(hstr);
        }


        var groupid = 0;

        $(window).ready(function () {

            var dateRange = new pickerDateRange('picker_date_range', {
                isTodayValid: true,
                defaultText: '  至  ',
                inputTrigger: 'input_trigger_demo3',
                success: function (obj) {
                    $("#picker_date_range").attr('datas', obj.startDate);
                    $("#picker_date_range").attr('datae', obj.endDate);
                },
                clear: function () {
                }
            });

            var daynow = new Date();
            daynow.setTime(daynow.getTime());
            var _s = daynow.Format("yyyy-MM-dd");
            var daylater = new Date();
            daylater.setTime(daylater.getTime() + 1000 * 3600*24);
            var _e = daylater.Format("yyyy-MM-dd");
            $("[name=daterange]").val(_s + " 至 " + _e);
            $("[name=daterange]").attr('datas', _s);
            $("[name=daterange]").attr('datae', _e);

            _apiget('/api/app/appInfo/options', false, (code, obj) => {
                if (code == 200) {
                    if (obj) {
                        if (obj.length > 0) {
                            var ahtml = '';
                            obj.forEach(item => {
                                ahtml += '<option value="' + item.appName + '">' + item.displayName + '</option>';
                            });
                            $("[name=appname]").html(ahtml);
                        }
                    }
                }
            });

            _readpagedata(1);

            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });



        });

        function _readpagedata(page) {

            if (page == 1) {
                $("#pagenumarea").html('');
            }

            var _info = $("#formsearch").parseForm();
            if (_info.daterange) {
                if (_info.daterange.length > 0) {
                    _info.sdate = $("[name=daterange]").attr('datas') + " 00:00:00";
                    _info.edate = $("[name=daterange]").attr('datae') + " 00:00:00";
                }
            }
            _info.page = page;
            _info.size = 30;

            _apipost("/api/app/Report/RankClientIp", true, JSON.stringify(_info), function (code, obj) {
                if (code == 200) {
                    var datas = obj.items;
                    _showpagedata(datas);
                    if (pageobject == null || page == 1) {
                        pageobject = new Page({
                            el: '#pagenumarea',
                            nums: obj.totalCount,//总数
                            counts: 30,//每页大小
                            defaultPage: 1,
                            showHeadFoot: false, // 显示首页尾页
                            head: '首', // 更改首页文字
                            foot: '尾', // 更改尾页文字
                            jumpToOrder: true, // 跳转到指定页
                            showNowAndAll: true, // 当前页/共几页
                            prev: "上一页",
                            next: "下一页",
                            clickEvent: function (currectPage, _this) {
                                _readpagedata(currectPage);
                            }
                        });
                    }
                }
            });
        }

        function _tosearch(word) {
            // $(".inputword").val("");
            $(".inputword").val(word);
            setTimeout(() => {
                _readpagedata(1);
            }, 300);
        }
    </script>
</body>

</html>